<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>

<script type="text/javascript">
	var sparepart = {
		gridId : "sparepartBackDetailGrid",
		saveUrl : "sparepart/sparepartChangeDetail/save"
	};
</script>

<script type="text/javascript" src="js/widget/sparepart.js"></script>

<form:form id="sparepartBackForm" commandName="model"
	cssClass="validate" action="sparepart/sparepartBack/save">
	<form:hidden path="id" />
	<table class=" form-table">
		<tr>
			<td class="td1">编号：</td>
			<td class="td2"><form:input path="code" disabled="true" /><span>
					(自动生成)</span></td>
			<td class="td1">归还日期：</td>
			<td class="td2"><form:input type="date" path="backDate"
					cssClass="required" /></td>
		</tr>
		<tr>
			<td class="td1">归还人：</td>
			<td class="td2"><form:hidden path="backManId" /> <isperp:departmentUser
					id="backManName" displayValue="${model.backManName }"
					afterSelected="afterSelected(row);" displayValueCssClass="required"
					name="backManName" valueControlId="backManId"></isperp:departmentUser>
			</td>
			<td class="td1">项目：</td>
			<td class="td2"><form:select path="projectId"
					items="${projects }" itemLabel="name" itemValue="id"
					cssClass="required search"></form:select></td>
		</tr>
		<tr>
			<td class="td1">归还类型：</td>
			<td class="td2" colspan="3">${model.type }
			</td>
		</tr>
		<tr>
			<td class="td1">描述：</td>
			<td class="td2" colspan="3"><form:textarea path="memo"
					cssClass="required" /> </textarea>
			</td>
		</tr>
		<tr>
			<td class="td1">填表人：</td>
			<td class="td2"><label>${creatorName }</label></td>
		</tr>
	</table>
</form:form>

<div id="sparepartBackFormDiv" style="display:none">
	<div class="header">
		<h3>
			归还<span style='color:red'>入库</span>清单
		</h3>
	</div>
	<isperp:sparepartChangeGrid relationId="${model.id }" typeKey="归还入库"
		formId="sparepartBackForm" id="sparepartBack">
	</isperp:sparepartChangeGrid>
</div>

<div id="sparepartDiscardFormDiv" style="display:none">
	<div class="header">
		<h3>
			归还<span style='color:red'>报废</span>清单
		</h3>
	</div>
	<isperp:sparepartChangeGrid relationId="${model.id }" typeKey="归还报废"
		formId="sparepartBackForm" id="sparepartDiscard">
	</isperp:sparepartChangeGrid>
</div>

<div id="sparepartRepairFormDiv" style="display:none">
	<div class="header">
		<h3>
			归还<span style='color:red'>维修</span>清单
		</h3>
	</div>
	<isperp:sparepartChangeGrid relationId="${model.id }" typeKey="归还维修" readonly="true"
		formId="sparepartBackForm" id="sparepartRepair">
	</isperp:sparepartChangeGrid>
</div>

<isperp:buttonList>
	<isperp:processButtons processKey="sparepartBackProcess"
		processId="${model.processId }" businessKey="${model.id }"
		formId="sparepartBackForm"></isperp:processButtons>
</isperp:buttonList>

<script type="text/javascript">
    choseType();
	function choseType() {
		var t = '${model.type}';
		if (t == "归还入库") {
			$("#sparepartBackFormDiv").show();
			$("#sparepartDiscardFormDiv").hide();
			$("#sparepartRepairFormDiv").hide();
		} else if (t == "归还报废") {
			$("#sparepartBackFormDiv").hide();
			$("#sparepartDiscardFormDiv").show();
			$("#sparepartRepairFormDiv").hide();
		} else if (t == "归还维修") {
			$("#sparepartBackFormDiv").hide();
			$("#sparepartDiscardFormDiv").hide();
			$("#sparepartRepairFormDiv").show();
		}
	}

	function afterSelected(row) {
		$.getJSON("project/member/listProjectByUsername?username=" + row[0], function(data) {

			$("#projectId").empty();
			if (data[0]) {
				$(data).each(function(index, item) {
					$("#projectId").append('<option value="'+item.id+'">' + item.name + '</option>');
				});
			}
			$("#projectId").trigger("chosen:updated");
		});
	}
</script>